const dbConfig = require("../config/db.config.js");
const Sequelize = require("sequelize");
const { Op, DataTypes } = require("sequelize");
const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD, {
    host: dbConfig.HOST,
    dialect: dbConfig.dialect,
    operatorsAliases: 0,
    timezone: '+08:00', //东八时区
    pool: {
        max: dbConfig.pool.max,
        min: dbConfig.pool.min,
        acquire: dbConfig.pool.acquire,
        idle: dbConfig.pool.idle
    }
});

const db = {};

db.Sequelize = Sequelize;//引入
db.sequelize = sequelize;//实例
db.Op = Op; //操作符

// 用户
const userModel = require("./user.model.js")(sequelize, DataTypes);
// 乡村
const villageModel = require("./village.model.js")(sequelize, DataTypes);
// 录入信息
const infoModel = require("./info.model.js")(sequelize, DataTypes);

userModel.belongsTo(villageModel, { foreignKey: 'villageId', targetKey: 'villageId' })

db.user = userModel
db.village = villageModel
db.info = infoModel

module.exports = db;
